<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Index</title>
    <style>
        html,
        body {
            margin: 0;
            padding: 0;
            height: 200vh;
            overflow-x: hidden;
        }

        .background {
            background-image: url("背景图.jpg");
            background-size: cover;
            background-position: 50% 50%;
            height: 200vh;
            font: 900 39rem '';
            line-height: 130vh;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            position: relative;
            text-align: center;
            overflow: hidden;
        }

        .background::before {
            content: '';
            background-size: cover;
            background-image: inherit;
            background-position: 50% 50%;
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            z-index: -99;
        }

        h1 {
            position: absolute;
            text-align: center;
            width: 100%;
            letter-spacing: 10px;
            color: #fff;
        }

        h2 {
            position: absolute;
            letter-spacing: 2px;
            top: 120vh;
            width: 60%;
            color: #fff;
            left: 50%;
            transform: translateX(-50%);
            padding: 30px;
            background-color: rgba(0, 0, 0, .3);
        }
    </style>
</head>

<body>
    <h1>滚动视觉差</h1>
    <div class="background"><span>王伟伦</span></div>
    <h2>
        烟雨中南朝四百八十寺依然屹立，断桥边红药黄花暗香如故，人面桃花不知何处，晓风残月仍伴杨柳，哀怨的风景令人心伤。在这诗的风景中，苏东坡于赤壁之上，伴江上之清风，高歌大江东去，叹人生如梦；柳三变于长亭古道，冷落清秋，执手相看泪眼，竟无语凝噎；李清照寻寻觅觅，于憔悴黄花之间，听梧桐更兼细雨，冷冷清清，凄凄惨惨戚戚。
    </h2>

    <script>
        const background = document.querySelector(".background")

        document.addEventListener('scroll', () => {
            const scrollY = window.scrollY

            if (scrollY !== 0) {
                background.style.backgroundPosition = `calc(50% + ${scrollY}px) calc(50% + ${scrollY}px)`
            }else{
                background.style.backgroundPosition = ''
            }
        })
    </script>
</body>

</html>